package com.lrl.security.validator;

import com.lrl.security.service.HelloService;
import com.lrl.security.service.impl.HelloServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Object> {

    @Autowired
    private HelloService helloService;
    /**
     *效验初始化
     * @param myConstraint
     */
    @Override
    public void initialize(MyConstraint myConstraint) {
        System.out.println("lrl validator init");
    }

    /**
     * 效验逻辑
     * @param o
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        helloService.greeting("LRL");
        System.out.println(o);
        return true;
    }
}
